//
//  NSModelDetailView.m
//  Meboo
//
//  Created by kyo on 2024/3/18.
//

#import "NSModelDetailView.h"
#import <TYCyclePagerView/TYCyclePagerView.h>
#import "NSDetailBannerCell.h"
#import "NSPageControlView.h"
#import "NSInterestsItemCell.h"
#import "NSString+Extension.h"
#import "TightnessFlowLayout.h"
@interface NSModelDetailView()
<
TYCyclePagerViewDelegate,
TYCyclePagerViewDataSource,
UICollectionViewDelegate,
UICollectionViewDataSource
>
//顶部轮播图
@property (nonatomic , strong) TYCyclePagerView *cycleScrollView;
//nearby online
@property(nonatomic,strong) UIButton *tagBtn1;
@property(nonatomic,strong) UIButton *tagBtn2;
//分页视图
@property (nonatomic, strong) NSPageControlView *pageControlView;
//下半部分背景图---容器视图
@property(nonatomic,strong) UIView *backView;
@property(nonatomic,strong) UIImageView *backImageView;
//name
@property(nonatomic,strong) UILabel *nameLab;
//AboutMe
@property(nonatomic,strong) UILabel *AboutMeLab;
//AboutMe 详情
@property(nonatomic,strong) UILabel *AboutMeSubLab;
//information
@property(nonatomic,strong) UILabel *informationLab;
//interests
@property(nonatomic,strong) UILabel *interestsLab;
//interests 列表视图
@property(nonatomic,strong) UICollectionView *collectionView;
//轮播图 顶部遮罩 --- 目的:防止图片未加载出来时,白底无法清楚显示pageview和online/nearby
@property (nonatomic, strong) UIView *topShadowView;
//轮播图 底部遮罩
@property (nonatomic, strong) UIView *bottomShadowView;
//socialConnections
@property(nonatomic,strong) UIButton *lookingBtn;
//身高inch 没有则不显示
@property(nonatomic,strong) UIButton *inchHeightBtn;
//星座,根据出生日期判断
@property(nonatomic,strong) UIButton *constellationBtn;
@end

@implementation NSModelDetailView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self setupUI];
        //作为UIScrollView子类的基础设置
        self.bounces = NO;
        self.showsVerticalScrollIndicator = NO;
        self.showsHorizontalScrollIndicator = NO;
        self.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }
    return self;
}

#pragma mark - Public Metohd
//处理传过来的模型数据 为当前页的内容赋值和子组件的信息传递
- (void)setModel:(NSUserInfoModel *)model {
    _model = model;
    
    if ([model.online isEqualToString:@"1"]) {
        self.tagBtn1.hidden = NO;
    } else {
        self.tagBtn1.hidden = YES;
    }
//    //分情况处理online/nearby
//    if ([model.online isEqualToString:@"1"] && ![model.nearby isEqualToString:@"1"]) {
//        //有online 无nearby
//        [self.tagBtn1 setTitle:@"Online" forState:0];
//        [self.tagBtn1 setImage:ImageWithName(@"home_list_online") forState:0];
//        self.tagBtn2.hidden = YES;
//        self.tagBtn1.hidden = NO;
//    } else if (![model.online isEqualToString:@"1"] && [model.nearby isEqualToString:@"1"]) {
//        //有nearby 无online
//        [self.tagBtn1 setTitle:@"Nearby" forState:0];
//        [self.tagBtn1 setImage:ImageWithName(@"home_list_nearby") forState:0];
//        self.tagBtn2.hidden = YES;
//        self.tagBtn1.hidden = NO;
//    } else if (![model.online isEqualToString:@"1"] && ![model.nearby isEqualToString:@"1"]) {
//        //无nearby 无online
//        self.tagBtn2.hidden = YES;
//        self.tagBtn1.hidden = YES;
//    } else {
//        //有nearby 有online
//        [self.tagBtn1 setTitle:@"Online" forState:0];
//        [self.tagBtn1 setImage:ImageWithName(@"home_list_online") forState:0];
//        [self.tagBtn2 setTitle:@"Nearby" forState:0];
//        [self.tagBtn2 setImage:ImageWithName(@"home_list_nearby") forState:0];
//        self.tagBtn2.hidden = NO;
//        self.tagBtn1.hidden = NO;
//    }
    self.nameLab.text = [NSString stringWithFormat:@"%@ · %@  ",model.nickName,model.age];
    
    //根据图片张数 设置pageView
    [self.pageControlView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(MBWidthScale(20)*model.images.count-MBWidthScale(4));
    }];
    self.pageControlView.totalNum = model.images.count;
    self.pageControlView.index = 0;
    
    
    if (model.images.count <= 1) {
        //单张无需轮播和滑动
        self.cycleScrollView.userInteractionEnabled = NO;
        self.cycleScrollView.autoScrollInterval = 10000;
    } else {
        //多张开始自动轮播和滑动
        self.cycleScrollView.userInteractionEnabled = YES;
        self.cycleScrollView.autoScrollInterval = 3;
    }
    [self.cycleScrollView reloadData];
    
    //AboutMe 文本设置
    self.AboutMeSubLab.text = model.aboutMe;
    
    //刷新interests列表
    [self.collectionView reloadData];
    
    //want 文本设置
    for (NSDictionary *dict in model.userWant) {
        if ([dict[@"select"] boolValue]) {
            [self.lookingBtn setTitle:[NSString stringWithFormat:@"%@",dict[@"value"]] forState:0];
        }
    }
    
    [self.inchHeightBtn setTitle:model.inchHeight forState:0];
    //有值显示 没值隐藏
    if (model.inchHeight.length > 0) {
        self.inchHeightBtn.hidden = NO;
        [self.inchHeightBtn setTitle:model.inchHeight forState:0];
    }
    [self.constellationBtn setTitle:[self constellationForDateStr:model.birthday] forState:0];
}

#pragma mark - Private Method
//根据日期返回星座
- (NSString *)constellationForDateStr:(NSString *)dateStr {
    //格式:04/12/1997
    if (dateStr.length < 10) {
        //格式不正确 返回默认值
        return @"Libra";
    }
    
    NSString *monthStr = [dateStr substringToIndex:2];
    NSString *dayStr = [dateStr substringFromIndex:2];
    dayStr = [dayStr substringToIndex:2];
    
    int month = [monthStr intValue];
    int day = [dayStr intValue];
    
    NSString *constellation = @"";
    if (month == 3 && day >= 21) {
        constellation = @"Aries";
    } else if (month == 4 && day <= 20) {
        constellation = @"Aries";
    } else if (month == 4 && day >= 20) {
        constellation = @"Taurus";
    } else if (month == 5 && day <= 20) {
        constellation = @"Taurus";
    } else if (month == 5 && day >= 21) {
        constellation = @"Gemini ";
    } else if (month == 6 && day <= 21) {
        constellation = @"Gemini ";
    } else if (month == 6 && day >= 22) {
        constellation = @"Cancer";
    } else if (month == 7 && day <= 22) {
        constellation = @"Cancer";
    } else if (month == 7 && day >= 23) {
        constellation = @"Leo";
    } else if (month == 8 && day <= 22) {
        constellation = @"Leo";
    } else if (month == 8 && day >= 23) {
        constellation = @"Virgo";
    } else if (month == 9 && day <= 22) {
        constellation = @"Virgo";
    } else if (month == 9 && day >= 23) {
        constellation = @"Libra";
    } else if (month == 10 && day <= 23) {
        constellation = @"Libra";
    } else if (month == 10 && day >= 24) {
        constellation = @"scorpio";
    } else if (month == 11 && day <= 22) {
        constellation = @"scorpio";
    } else if (month == 11 && day >= 23) {
        constellation = @"Sagittarius";
    } else if (month == 12 && day <= 21) {
        constellation = @"Sagittarius";
    } else if (month == 12 && day >= 22) {
        constellation = @"Capricorn";
    } else if (month == 1 && day <= 19) {
        constellation = @"Capricorn";
    } else if (month == 1 && day >= 20) {
        constellation = @"Aquarius";
    } else if (month == 2 && day <= 18) {
        constellation = @"Aquarius";
    } else {
        constellation = @"Pisces";
    }
    return constellation;
}

#pragma mark - Action

#pragma mark - TYCyclePagerViewDataSource
- (NSInteger)numberOfItemsInPagerView:(TYCyclePagerView *)pageView {
    if (self.model.images.count > 0) {
        return self.model.images.count;
    }
    return 1;
}

- (UICollectionViewCell *)pagerView:(TYCyclePagerView *)pagerView cellForItemAtIndex:(NSInteger)index {
    
    NSDetailBannerCell *cell = [pagerView dequeueReusableCellWithReuseIdentifier:@"NSDetailBannerCell" forIndex:index];
    if (self.model.images.count > 0) {
        [cell.iconImageView sd_setImageWithURL:[NSURL URLWithString:self.model.images[index]]];
    } else {
        [cell.iconImageView sd_setImageWithURL:[NSURL URLWithString:self.model.avatarUrl]];
    }
    
    return cell;
}

- (TYCyclePagerViewLayout *)layoutForPagerView:(TYCyclePagerView *)pageView {
    TYCyclePagerViewLayout *layout = [[TYCyclePagerViewLayout alloc]init];
    layout.itemSize = CGSizeMake(CGRectGetWidth(pageView.frame), CGRectGetHeight(pageView.frame));
    layout.itemSpacing = 0;
    return layout;
}

- (void)pagerView:(TYCyclePagerView *)pageView didScrollFromIndex:(NSInteger)fromIndex toIndex:(NSInteger)toIndex {
    self.pageControlView.index = toIndex;
}

#pragma mark -- TYCyclePagerViewDelegate
- (void)pagerView:(TYCyclePagerView *)pageView didSelectedItemCell:(__kindof UICollectionViewCell *)cell atIndex:(NSInteger)index {
    [pageView scrollToNearlyIndexAtDirection:TYPagerScrollDirectionRight animate:YES];
}


#pragma mark -- collectionView  delegate datasource
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.model.interests.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    NSInterestsItemCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"NSInterestsItemCell" forIndexPath:indexPath];
    NSString *titleStr = [NSString stringWithFormat:@"%@",self.model.interests[indexPath.row]];
    [cell.titleBtn setTitle:titleStr forState:0];
    return cell;
}

//设置每个section的UIEdgeInsets
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
    return UIEdgeInsetsMake(MBHeightScale(0), MBWidthScale(0), MBHeightScale(0), MBWidthScale(0));
}

//设置列间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
    return MBWidthScale(8);
}

//设置每个item水平间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
    return MBHeightScale(8);
}

//定义每一个cell的大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    NSString *titleStr = self.model.interests[indexPath.row];
    //此方法根据文本内容和字号生成size
    CGSize size = [titleStr sizeWithFont:MBHelFontSizeScale(15) maxSize:CGSizeMake(ScreenWidth-MBWidthScale(50), MBHeightScale(28))];
    return CGSizeMake(size.width+MBWidthScale(20), MBHeightScale(28));
}

#pragma mark - UI
- (void)setupUI {
    self.backgroundColor = [UIColor colorWithPatternImage:ImageWithName(@"model_detail_back_image")];
    
    [self addSubview:self.cycleScrollView];
    [self.cycleScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.equalTo(self);
        make.width.mas_equalTo(ScreenWidth);
        make.height.mas_equalTo(ScreenWidth*367/375);
    }];
    
    [self addSubview:self.topShadowView];
    [self.topShadowView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.equalTo(self);
        make.width.mas_equalTo(ScreenWidth);
        make.height.mas_equalTo(StatusBarAndNavigationBarHeight);
    }];
    
    [self addSubview:self.bottomShadowView];
    [self.bottomShadowView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self);
        make.width.mas_equalTo(ScreenWidth);
        make.bottom.equalTo(self.cycleScrollView);
        make.height.mas_equalTo(MBHeightScale(80));
    }];
    
    [self addSubview:self.pageControlView];
    [self.pageControlView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.cycleScrollView);
        make.centerY.equalTo(self.mas_top).offset(StatusBarHeight+MBHeightScale(22));
        make.height.mas_equalTo(MBHeightScale(4));
    }];
    
    [self addSubview:self.tagBtn1];
    [self.tagBtn1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.bottomShadowView);
        make.left.mas_equalTo(MBWidthScale(25));
    }];
    
    [self addSubview:self.tagBtn2];
    [self.tagBtn2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.tagBtn1);
        make.left.equalTo(self.tagBtn1.mas_right).offset(MBWidthScale(16));
    }];
    
    [self addSubview:self.backView];
    [self.backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.cycleScrollView.mas_bottom).offset(MBHeightScale(-20));
        make.left.equalTo(self);
        make.width.mas_equalTo(ScreenWidth);
        make.bottom.mas_equalTo(TabbarSafeBottomMargin);
    }];
    
//    [self.backView addSubview:self.backImageView];
//    [self.backImageView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.edges.equalTo(self.backView);
//    }];
    
    [self.backView addSubview:self.nameLab];
    [self.nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(MBWidthScale(25));
        make.width.mas_equalTo(ScreenWidth-MBWidthScale(50));
        make.top.mas_equalTo(MBHeightScale(25));
    }];
    
//    [self addSubview:self.AboutMeLab];
//    [self.AboutMeLab mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.mas_equalTo(MBWidthScale(25));
//        make.top.equalTo(self.nameLab.mas_bottom).offset(MBHeightScale(10));
//    }];
    
    [self.backView addSubview:self.AboutMeSubLab];
    [self.AboutMeSubLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(MBWidthScale(25));
        make.width.mas_equalTo(ScreenWidth-MBWidthScale(50));
//        make.top.equalTo(self.AboutMeLab.mas_bottom).offset(MBHeightScale(10));
        make.top.equalTo(self.nameLab.mas_bottom).offset(MBHeightScale(10));
    }];
    
    [self.backView addSubview:self.informationLab];
    [self.informationLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(MBWidthScale(25));
        make.top.equalTo(self.AboutMeSubLab.mas_bottom).offset(MBHeightScale(22));
    }];
    
    [self.backView addSubview:self.lookingBtn];
    [self.lookingBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(MBWidthScale(25));
        make.top.equalTo(self.informationLab.mas_bottom).offset(MBHeightScale(10));
    }];
    
    [self.backView addSubview:self.inchHeightBtn];
    [self.inchHeightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.lookingBtn.mas_right).offset(MBWidthScale(20));
        make.centerY.equalTo(self.lookingBtn);
    }];
    
    [self.backView addSubview:self.constellationBtn];
    [self.constellationBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(MBWidthScale(25));
        make.top.equalTo(self.lookingBtn.mas_bottom).offset(MBHeightScale(8));
    }];
    
    [self.backView addSubview:self.interestsLab];
    [self.interestsLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(MBWidthScale(25));
        make.top.equalTo(self.constellationBtn.mas_bottom).offset(MBHeightScale(25));
    }];
    
    [self.backView addSubview:self.collectionView];
    [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(MBWidthScale(25));
        make.width.mas_equalTo(ScreenWidth-MBWidthScale(50));
        make.top.equalTo(self.interestsLab.mas_bottom).offset(MBHeightScale(15));
        make.height.mas_equalTo(MBHeightScale(100));
        make.bottom.mas_equalTo(MBHeightScale(-80)-TabbarSafeBottomMargin);
    }];
    
    [self.backView layoutIfNeeded];
    //渐变色 设置开始和结束位置(设置渐变的方向)
    CAGradientLayer *gradient = [CAGradientLayer layer];
    gradient.startPoint = CGPointMake(0, 0.5);
    gradient.endPoint = CGPointMake(1, 0.5);
    gradient.locations = @[@(0.0),@(1.0f)];
    gradient.frame =CGRectMake(0,0,self.backView.bounds.size.width,self.backView.bounds.size.height);
    gradient.colors = [NSArray arrayWithObjects:(id)HEXS(@"F7F5FF").CGColor,(id)HEXS(@"F4F2FF").CGColor,nil];
    [self.backView.layer insertSublayer:gradient atIndex:0];
//    NSLog(@"&*&*&*%f,%f",self.backView.bounds.size.width,self.backView.bounds.size.height);
//        [self.backView addSubview:self.backImageView];
//        [self.backImageView mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.center.equalTo(self.backView);
//            make.width.mas_equalTo(self.backView.bounds.size.width);
//            make.height.mas_equalTo(self.backView.bounds.size.height);
//        }];
//    [self.backView sendSubviewToBack:self.backImageView];
    
//部分圆角的bottomShadowView 本次不需要,暂时注释
//    [self.bottomShadowView layoutIfNeeded];
//    UIBezierPath *maskPath;
//    maskPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, ScreenWidth, MBHeightScale(35)) byRoundingCorners:(UIRectCornerBottomLeft | UIRectCornerBottomRight) cornerRadii:CGSizeMake(MBHeightScale(18),MBHeightScale(18))];//圆角大小
//    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
//    maskLayer.frame = CGRectMake(0, 0, ScreenWidth, MBHeightScale(35));
//    maskLayer.path = maskPath.CGPath;
//    self.bottomShadowView.layer.mask = maskLayer;
}

#pragma mark - Setter && Getter

- (UIButton *)tagBtn1 {
    if (!_tagBtn1) {
        _tagBtn1 = [UIButton leftimageAndRighttitlePatternWithImage:@"home_list_online" AndMargin:4 AndTitle:@"Online" AndTitleFont:MBHelFontSizeScale(16) AndTitleColor:HEXS(@"ffffff")];
        _tagBtn1.hidden = YES;
    }
    return _tagBtn1;
}

- (UIButton *)tagBtn2 {
    if (!_tagBtn2) {
        _tagBtn2 = [UIButton leftimageAndRighttitlePatternWithImage:@"home_list_nearby" AndMargin:4 AndTitle:@"Nearby" AndTitleFont:MBHelFontSizeScale(16) AndTitleColor:HEXS(@"ffffff")];
        _tagBtn2.hidden = YES;
    }
    return _tagBtn2;
}

- (TYCyclePagerView *)cycleScrollView {
    if (!_cycleScrollView) {
        _cycleScrollView = [[TYCyclePagerView alloc] init];
        _cycleScrollView.layer.cornerRadius = MBHeightScale(2);
        _cycleScrollView.layer.masksToBounds = YES;
        _cycleScrollView.isInfiniteLoop = YES;
        _cycleScrollView.delegate = self;
        _cycleScrollView.dataSource = self;
        _cycleScrollView.backgroundColor = [UIColor clearColor];
        _cycleScrollView.autoScrollInterval = 3;
        _cycleScrollView.reloadDataNeedResetIndex = YES;
        [_cycleScrollView registerClass:[NSDetailBannerCell class] forCellWithReuseIdentifier:@"NSDetailBannerCell"];
    }
    return _cycleScrollView;
}

- (NSPageControlView *)pageControlView {
    if (!_pageControlView) {
        _pageControlView = [NSPageControlView new];
    }
    return _pageControlView;
}

- (UILabel *)AboutMeLab {
    if (!_AboutMeLab) {
        _AboutMeLab = [UILabel new];
        _AboutMeLab.text = @"About me";
        _AboutMeLab.font = PDSemiBoldScale(15);
        _AboutMeLab.textColor = HEXS(@"B92176");
    }
    return _AboutMeLab;
}

- (UILabel *)AboutMeSubLab {
    if (!_AboutMeSubLab) {
        _AboutMeSubLab = [UILabel new];
        _AboutMeSubLab.text = @"";
        _AboutMeSubLab.numberOfLines = 0;
        _AboutMeSubLab.font = MBHelFontSizeScale(13);
        _AboutMeSubLab.textColor = HEXS(@"666666");
    }
    return _AboutMeSubLab;
}

- (UILabel *)nameLab {
    if (!_nameLab) {
        _nameLab = [UILabel new];
        _nameLab.numberOfLines = 0;
        _nameLab.font = MBHelBoldFontSizeScale(24);
        _nameLab.textColor = HEXS(@"000000");
    }
    return _nameLab;
}

- (UILabel *)informationLab {
    if (!_informationLab) {
        _informationLab = [UILabel new];
        _informationLab.text = @"Personal information";
        _informationLab.font = MBHelBoldFontSizeScale(15);
        _informationLab.textColor = HEXS(@"000000");
    }
    return _informationLab;
}

- (UILabel *)interestsLab {
    if (!_interestsLab) {
        _interestsLab = [UILabel new];
        _interestsLab.text = @"Interests";
        _interestsLab.font = MBHelBoldFontSizeScale(15);
        _interestsLab.textColor = HEXS(@"000000");
    }
    return _interestsLab;
}

- (UICollectionView *)collectionView {
    if (!_collectionView) {
        TightnessFlowLayout *flowLayout = [[TightnessFlowLayout alloc] init];
        _collectionView = [[UICollectionView alloc] initWithFrame:self.bounds collectionViewLayout:flowLayout];
        _collectionView.backgroundColor = UIColor.clearColor;
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        _collectionView.showsVerticalScrollIndicator = NO;
        _collectionView.showsHorizontalScrollIndicator = NO;
        [_collectionView registerClass:[NSInterestsItemCell class] forCellWithReuseIdentifier:@"NSInterestsItemCell"];
    }
    return _collectionView;
}


- (UIView *)topShadowView {
    if (!_topShadowView) {
        _topShadowView = [UIView new];
        //渐变色 设置开始和结束位置(设置渐变的方向)
        CAGradientLayer *gradient = [CAGradientLayer layer];
        gradient.startPoint = CGPointMake(0, 0);
        gradient.endPoint = CGPointMake(0, 1);
        gradient.locations = @[@(0.0),@(1.0f)];
        gradient.frame =CGRectMake(0,0,ScreenWidth,StatusBarAndNavigationBarHeight);
        gradient.colors = [NSArray arrayWithObjects:(id)[UIColor colorWithRed:0 / 255.0 green:0 / 255.0 blue:0 / 255.0 alpha:0.5].CGColor,(id)[UIColor colorWithRed:0 / 255.0 green:0 / 255.0 blue:0 / 255.0 alpha:0].CGColor,nil];
        [_topShadowView.layer insertSublayer:gradient atIndex:0];
    }
    return _topShadowView;
}

//- (UIImageView *)bottomShadowView {
//    if (!_bottomShadowView) {
//        _bottomShadowView = [UIImageView new];
//        _bottomShadowView.image = ImageWithName(@"home_modeldetail_shadow");
//    }
//    return _bottomShadowView;
//}

- (UIView *)bottomShadowView {
    if (!_bottomShadowView) {
        _bottomShadowView = [UIView new];
        //渐变色 设置开始和结束位置(设置渐变的方向)
        CAGradientLayer *gradient = [CAGradientLayer layer];
        gradient.startPoint = CGPointMake(0, 0);
        gradient.endPoint = CGPointMake(0, 1);
        gradient.locations = @[@(0.0),@(1.0f)];
        gradient.frame =CGRectMake(0,0,ScreenWidth,MBHeightScale(80));
        gradient.colors = [NSArray arrayWithObjects:(id)[UIColor colorWithRed:0 / 255.0 green:0 / 255.0 blue:0 / 255.0 alpha:0].CGColor,(id)[UIColor colorWithRed:0 / 255.0 green:0 / 255.0 blue:0 / 255.0 alpha:0.5].CGColor,nil];
        [_bottomShadowView.layer insertSublayer:gradient atIndex:0];
    }
    return _bottomShadowView;
}

- (UIView *)backView {
    if (!_backView) {
        _backView = [UIView new];
        _backView.layer.cornerRadius = MBHeightScale(23);
        _backView.layer.masksToBounds = YES;
        _backView.backgroundColor =[UIColor clearColor];
    }
    return _backView;
}

- (UIImageView *)backImageView {
    if (!_backImageView) {
        _backImageView = [UIImageView new];
        _backImageView.layer.cornerRadius = MBHeightScale(23);
        _backImageView.layer.masksToBounds = YES;
        _backImageView.clipsToBounds = YES;
        _backImageView.contentMode = UIViewContentModeScaleToFill;
        _backImageView.image = ImageWithName(@"model_detail_back_image");
    }
    return _backImageView;
}

- (UIButton *)lookingBtn {
    if (!_lookingBtn) {
        _lookingBtn = [UIButton leftimageAndRighttitlePatternWithImage:@"modeldetail_socialConnections" AndMargin:MBWidthScale(7) AndTitle:@"Looking for a dating partner" AndTitleFont:MBHelFontSizeScale(13) AndTitleColor:HEXS(@"666666")];
    }
    return _lookingBtn;
}

- (UIButton *)inchHeightBtn {
    if (!_inchHeightBtn) {
        _inchHeightBtn = [UIButton leftimageAndRighttitlePatternWithImage:@"modeldetail_inchheight" AndMargin:MBWidthScale(7) AndTitle:@"3'08" AndTitleFont:MBHelFontSizeScale(13) AndTitleColor:HEXS(@"666666")];
        _inchHeightBtn.hidden = YES;
    }
    return _inchHeightBtn;
}

- (UIButton *)constellationBtn {
    if (!_constellationBtn) {
        _constellationBtn = [UIButton leftimageAndRighttitlePatternWithImage:@"modeldetail_constellation" AndMargin:MBWidthScale(7) AndTitle:@"Libra" AndTitleFont:MBHelFontSizeScale(13) AndTitleColor:HEXS(@"666666")];
    }
    return _constellationBtn;
}
@end
